<?php
	function isValidEmail($email){
	return eregi("^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$", $email);
	}
	$qr_OBJ = $_POST['CliNumero'];
	if ($_POST['CliTelefono'] > 0 || $_POST['CliTelefono2'] > 0) {
		$ACFi12 = req_form(cleanchars($_POST['CliTelefono']));
		$ACFi13 = req_form(cleanchars($_POST['CliTelefono2']));
	 } else {$Msg_ERROR = "Indique um contacto do Cliente";}
	 $ACFi30 = req_form(strtolower(cleanchars($_POST['CLCttEmail'])));
	 if (isValidEmail($ACFi30)==false) {
		$Msg_ERROR = "Indique um endereco de email valido.";
	 }
	 if (!isset($Msg_ERROR)) {

		$OldData = $GLOBALS['MYT']->db_array("SELECT CliTelefono, CliTelefono2, CLCttEmail FROM clientes WHERE CliNumero = {$qr_OBJ}");
	if($OldData[1]['CliTelefono'] != $ACFi12 || $OldData[1]['CliTelefono2'] != $ACFi13 || $OldData[1]['CLCttEmail'] != $ACFi30) {
		if($GLOBALS['MYT']->db_query("UPDATE clientes SET CliTelefono = {$ACFi12}, CliTelefono2 = {$ACFi13}, CLCttEmail = '{$ACFi30}' WHERE CliNumero = {$qr_OBJ}")==true) {
		include($GLOBALS['BIB'].'Pr_db/pr_historics.mex');
		hs_client($qr_OBJ,$sysTime);
		}
	}
		if (isset($_GET['or_rpt'])) {

				$DocModude = $_POST['rsp_Module'];
				$DocMethod = '01';
				$DocObjct = $_POST['rsp_obID'];
				$DocFileFolder = $GLOBALS['DOC'].'TRS_DIGRCP/';
				$DocFilename = $DocObjct.'.pdf';
				$Qunt = 1;
			$Mail_Receiver = '';
			$Mail_Attch = '';
			$Mail_Subject = 'Recibo de Remessa -'.Empresa::getNome();
			$Mail_Text = 'A '.Empresa::getNome().' envia-lhe o recibo da remessa efectuada, guarde ou imprima este documento.';
			// gen file
			include($GLOBALS['PAD'].'Aplications/Export_Pdf.mex');
			$Mail_Attch = $DocFileFolder.$DocFilename;

			// send mail
			include($GLOBALS['PAD'].'Aplications/Contact_Email.mex');

		echo '<script charset="utf-8" type=\"text/javascript\">newprint(\''.$GLOBALS['APP'].'Export_Print.mex?MOD='.$_POST['rsp_Module'].'&OB='.$_POST['rsp_obID'].'&ID=01\',\'Printer\');</script>';
		}

	} else {

	echo '<div class="Error">'.$Msg_ERROR.'</div>';
	}